package com.backend.service.impl;

import com.backend.pojo.entity.CourseMaterial;
import com.backend.mapper.CourseMaterialMapper;
import com.backend.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {


    @Autowired
    private CourseMaterialMapper courseMaterialMapper ;

    @Override
    public List<CourseMaterial> CourseQuery(CourseMaterial courseMaterial) {

        List<CourseMaterial> courseMaterialList =  courseMaterialMapper.CourseQuery(courseMaterial);

        return courseMaterialList;
    }


    @Override
    public void add(CourseMaterial courseMaterial) {
        courseMaterial.setUploadTime(LocalDateTime.now());
        courseMaterialMapper.add(courseMaterial);
        System.out.println("插入后的 ID: " + courseMaterial.getId());  // 验证 ID 是否更新
    }

    @Override
    public void deleteById(Integer id) {
        courseMaterialMapper.deleteById(id);
    }

    @Override
    public void update(CourseMaterial courseMaterial) {
        courseMaterial.setUploadTime(LocalDateTime.now());
        courseMaterialMapper.update(courseMaterial);
    }

    @Override
    public List<CourseMaterial> getAll() {
        List<CourseMaterial> courseMaterialList =  courseMaterialMapper.getAll();

        return courseMaterialList;
    }


}